package com.ktjy.controller;

import com.ktjy.entity.User;
import com.ktjy.vo.UserVo;
import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/user")
public class UserController {
    Logger logger = LoggerFactory.getLogger(UserController.class);

//    @RequestMapping("/list")
//    public String list(HttpServletRequest request, Model model) {
//        String name=request.getParameter("name");
//        String age=request.getParameter("age");
//        logger.info("list方法进来了,请求参数name={},age={}",name,age);
//        List<User> list=new ArrayList<>();
//        list.add(new User(1,"张三",18));
//        list.add(new User(2,"李四",19));
//        list.add(new User(3,"王五",20));
//        model.addAttribute("list",list);
//        return "list";
//    }

    @RequestMapping("/list")
    public String list(HttpServletRequest request, Map<String,Object> map) {
        String name=request.getParameter("name");
        String age=request.getParameter("age");
        logger.info("list方法进来了,请求参数name={},age={}",name,age);
        List<User> list=new ArrayList<>();
        list.add(new User(1,"张三",18));
        list.add(new User(2,"李四",19));
        list.add(new User(3,"王五",20));
        map.put("list",list);
        return "list";
    }

    @RequestMapping("/view")
    public String view(@RequestParam("id") Integer id) {
        logger.info("view方法进来了" + id);
        return null;
    }

    @RequestMapping("/add")
    public String add(){
        logger.info("qwsqs");
        return "add";
    }

    @RequestMapping("/save")
    public String save(User user) {
        logger.info("save方法进来了:接收参数name={}，age={}",
                user.getName(), user.getAge());
        return null;
    }

    @RequestMapping("/toDelete")
    public String toDelete(){
        return "delete";
    }

    @RequestMapping("/delete")
    public String delete(@RequestParam("ids") String[] ids){
        logger.info("delete方法进来了:接收参数ids={}", Arrays.asList(ids));
        return null;
    }

    @RequestMapping("/edit")
    public String edit(){
        return "edit";
    }

    @RequestMapping("/update")
    public String update(UserVo userVo){
        logger.info("update方法进来了:接收参数users={}", userVo.getUsers());
        return null;
    }
}
